package tr.edu.metu.is.mega.client.service;

import tr.edu.metu.is.mega.common.dto.UserDTO;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * GWT authentication service.
 */
@RemoteServiceRelativePath("../GwtAuthenticationService")
public interface GwtAuthenticationService extends RemoteService {

    /**
     * Utility class for simplifying access to the instance of async service.
     */
    public static class Util {

        private static GwtAuthenticationServiceAsync instance;

        /**
         * Initiates and returns singleton instance of service.
         * 
         * @return singleton instance of service
         */
        public static GwtAuthenticationServiceAsync getInstance() {
            if (instance == null) {
                instance = GWT.create(GwtAuthenticationService.class);
            }
            return instance;
        }
    }

    /**
     * Logins user with user id/password.
     * 
     * @param userName user name
     * @param password password
     * @return logged in user
     */
    UserDTO login(String userName, String password);

    /**
     * Returns current user information.
     * 
     * @return current user information
     */
    UserDTO getCurrentUser();

    /**
     * Returns user information stored in session (if-any).
     * 
     * @return {@link UserDTO} from session
     */
    UserDTO getFromSession();

    /**
     * Logouts current user from session.
     */
    void logout();

    /**
     * Updates session when user is changed.
     * 
     * @param user
     */
    void updateCurrentUser(UserDTO user);

}
